package com.miaosha.ms_04.result;

/**
 * @author hezhaoxiang
 * @Description //异常返回对象
 * @Date 10:19 2020/9/13
 **/
public class CodeMsg {

    private int code;

    private String msg;

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public static CodeMsg SUCCESS = new CodeMsg(200, "操作成功");
    public static CodeMsg SERVER_ERR = new CodeMsg(500100, "服务端异常");

    //5002xx 登陆异常
    public static CodeMsg SESSION_ERROR = new CodeMsg(500210, "Session 不存在");
    public static CodeMsg USER_EXIST = new CodeMsg(500211, "该用户不存在");
    public static CodeMsg PASSWORD_EMPTY = new CodeMsg(500212, "密码不能为空");
    public static CodeMsg PASSWORD_ERROR = new CodeMsg(500213, "密码不正确");
    public static CodeMsg MOBILE_EMPTY = new CodeMsg(500214, "手机号不能为空");
    public static CodeMsg MOBILE_ERROR = new CodeMsg(500215, "手机号格式异常");
    public static CodeMsg MOBILE_NOT_EXIST = new CodeMsg(500216, "手机号不存在");
    public static CodeMsg USER_EMPTY = new CodeMsg(500217, "用户不能为空");



    //输入格式有误，需要传入参数，形成比如 输入格式有误：手机号码格式异常
    public static CodeMsg INPUT_ERROR = new CodeMsg(500217, "输入格式有误:%s");
    public static CodeMsg PARAM_EMPTY = new CodeMsg(500218, "%s 不能为空");

    //订单 500300 订单异常
    public static CodeMsg GOOD_ID_EMPTY = new CodeMsg(500300, "商品ID不能为空");
    public static CodeMsg GOOD_NOT_EXIST = new CodeMsg(500301, "订单ID不能为空");
    public static CodeMsg ORDER_ID_EMPTY = new CodeMsg(500302, "订单ID不能为空");
    public static CodeMsg STOCK_NOT_ENOUGH = new CodeMsg(500303, "商品库存不足");
    public static CodeMsg ORDER_REPEAT = new CodeMsg(500304, "该用户已购买过，不能重复购买");


    private CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * @param params 说明内容
     * @return com.miaosha.ms_02.result.CodeMsg
     * @Description
     **/
    public static CodeMsg fillArgs(Object... params) {
        CodeMsg cm = INPUT_ERROR;
        //运用String 自带的字符串拼接，params 追加在 msg　之后
        String msg = String.format(INPUT_ERROR.getMsg(), params);
        return new CodeMsg(cm.getCode(), msg);
    }

    public static CodeMsg fillParamEmptyArgs(Object... params) {
        CodeMsg cm = PARAM_EMPTY;
        String msg = String.format(cm.getMsg(), params);
        return new CodeMsg(cm.getCode(), msg);
    }
}
